// 这份代码专门处理逻辑层的操作
const censusDao = require('../dao/censusDao');

const powerService = require('./powerService');

const censusService = {
    /*
     * 查询某个学生的所有测评记录
     */
    async getAssessRecordsByStudentId(uid, userType, studentId) {
        // 用户权限认证
        let result;
        try {
            result = await powerService.checkPowerByUid(uid, '查看学生信息');
            if (result == false) {
                return {success: false, msg: "权限不足，无法操作"};
            }
        } catch (err) {
            return {success: false, msg: "操作过程中出错"};
        }
        let func = (userType == '' || userType == '') ? censusDao.getAssessRecordsByStudentIdOfFaculty : censusDao.getAssessRecordsByStudentId;
        // 真正的执行逻辑
        try {
            result = await func(uid, studentId);
            result = { success: true, msg: "查询成功", result };
        } catch (error) {
            result = { success: false, msg: "查询数据库时出错，查询失败" };
        }
        return result;
    },
};

module.exports = censusService;